package com.ruoyi.web.controller.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.system.domain.TProScanningmaterial;
import com.ruoyi.system.service.ITProScanningmaterialService;
import com.ruoyi.web.controller.tool.Params;

/**
 * 扫描物料 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-02-20
 */
@Controller
@RequestMapping("/system/tProScanningmaterial")
public class TProScanningmaterialController extends BaseController
{
    private String prefix = "system/tProScanningmaterial";
	
	@Autowired
	private ITProScanningmaterialService tProScanningmaterialService;
	
	@GetMapping()
	public String tProScanningmaterial(String plancode)
	{
		Params.plancode = plancode ;
	    return prefix + "/tProScanningmaterial";
	}
	
	/**
	 * 查询扫描物料列表
	 */
	@RequestMapping("/list")
	@ResponseBody
	public TableDataInfo list(TProScanningmaterial tProScanningmaterial)
	{
		if(Params.plancode != null ) {
			tProScanningmaterial.setPlancode(Params.plancode);
		}
		startPage();
        List<TProScanningmaterial> list = tProScanningmaterialService.selectTProScanningmaterialList(tProScanningmaterial);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出扫描物料列表
	 */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TProScanningmaterial tProScanningmaterial)
    {
    	List<TProScanningmaterial> list = tProScanningmaterialService.selectTProScanningmaterialList(tProScanningmaterial);
        ExcelUtil<TProScanningmaterial> util = new ExcelUtil<TProScanningmaterial>(TProScanningmaterial.class);
        return util.exportExcel(list, "tProScanningmaterial");
    }
	
	/**
	 * 新增扫描物料
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存扫描物料
	 */
	@Log(title = "扫描物料", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TProScanningmaterial tProScanningmaterial)
	{		
		return toAjax(tProScanningmaterialService.insertTProScanningmaterial(tProScanningmaterial));
	}

	/**
	 * 修改扫描物料
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		TProScanningmaterial tProScanningmaterial = tProScanningmaterialService.selectTProScanningmaterialById(id);
		mmap.put("tProScanningmaterial", tProScanningmaterial);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存扫描物料
	 */
	@Log(title = "扫描物料", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TProScanningmaterial tProScanningmaterial)
	{		
		return toAjax(tProScanningmaterialService.updateTProScanningmaterial(tProScanningmaterial));
	}
	
	/**
	 * 删除扫描物料
	 */
	@Log(title = "扫描物料", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(tProScanningmaterialService.deleteTProScanningmaterialByIds(ids));
	}
	
}
